package com.base_data_handler.utils;

import java.io.File;
import java.io.FilenameFilter;

public class DirFilter implements FilenameFilter {

	private String type;

	public DirFilter(String tp) {

		this.type = tp;

	}

	@Override
	public boolean accept(File dir, String path) {
		File file = new File(path);

		String filename = file.getName();

		return filename.indexOf(type) != -1;
	}

	public static void main(String[] args) {

		try {

			// 指定目录(“.”表示当前目录)

			File dir = new File("C:/Users/Administrator/Desktop/app");

			String[] names;

			// 获得所有java文件

			DirFilter filter = new DirFilter(".png");

			names = dir.list(filter);

			// 打印所有java文件名称

			for (int i = 0; i < names.length; i++) {

				System.out.println("i:" + i + " name:" + names[i]);

			}

		} catch (Exception e) {

			e.printStackTrace();

		}

	}
}